package com.atguigu.gmall.juc.atomic;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/1 11:03
 */
public class AtomicTest implements Runnable{
    private static AtomicInteger atomicInteger = new AtomicInteger();
    private static int number = 0;
    private void add(){
        atomicInteger.addAndGet(20);
    }
    private void addnumber(){
        number++;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            add();
            addnumber();
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        Thread thread = new Thread(new AtomicTest());
//        Thread thread2 = new Thread(new AtomicTest());
//        thread.start();
//        thread2.start();
//        thread.join();
//        thread2.join();
//        System.out.println(atomicInteger.get());
//        System.out.println(number);
        HashMap<String,String> map = new HashMap<>();
        ConcurrentHashMap<String,String> concurrentHashMap = new ConcurrentHashMap<>();
        map.put(null,"123");
        System.out.println(map);
        concurrentHashMap.put(null,"123");
        System.out.println(concurrentHashMap);
    }
}
